package com.learn.mail.config;


import org.beetl.core.resource.ClasspathResourceLoader;

import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 配置类
 * @author:         MI
 * @email:          448341911@qq.com
 * @createTime:     2023/12/16 19:01
 * @updateUser:     cong zhi
 * @updateTime:     2023/12/16 19:01
 * @updateRemark:   修改内容
 * @version:        v1.0
 */
@Configuration
@EnableConfigurationProperties(BeetlProperties.class)
public class BeetlConfig {

    @Resource
    private BeetlProperties beetlProperties;

    /**
     * beetl的配置
     */
    @Bean(initMethod = "init")
    public BeetlConfiguration beetlConfiguration() {
        BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
        beetlConfiguration.setResourceLoader(new ClasspathResourceLoader(BeetlConfig.class.getClassLoader(), beetlProperties.getPrefix()));
        beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
        return beetlConfiguration;
    }

    /**
     * beetl的视图解析器
     */
    @Bean
    public BeetlSpringViewResolver beetlViewResolver() {
        BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
        beetlSpringViewResolver.setConfig(beetlConfiguration());
//        beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
//        beetlSpringViewResolver.setOrder(0);
        return beetlSpringViewResolver;
    }
}
